package com.zhika.zishi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhika.zishi.R;

import java.util.ArrayList;

/**
 * Created by shi-02 on 2015/4/23.
 */
public class MySelfLikeStrategyAdapter extends BaseAdapter {

    private ArrayList<MySelfLikeStrategyBean> likeStrategyBeans;

    private Context context;

    public MySelfLikeStrategyAdapter(Context context, ArrayList<MySelfLikeStrategyBean> likeStrategyBeans) {
        this.context = context;

        this.likeStrategyBeans = likeStrategyBeans;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public int getCount() {
        return likeStrategyBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder viewHolder;
        if (convertView == null){
            view = LayoutInflater.from(context).inflate(R.layout.item_of_myself_like_strategy,null);
            viewHolder = new ViewHolder();
            viewHolder.strategyTitleText = (TextView) view.findViewById(R.id.item_of_myself_like_strategy_title_text);
            viewHolder.nicknameText = (TextView) view.findViewById(R.id.item_of_myself_like_strategy_nickname_text);

            view.setTag(viewHolder);
        }else {
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
            resetViewHolder(viewHolder);
        }

        MySelfLikeStrategyBean bean = likeStrategyBeans.get(position);

        viewHolder.strategyTitleText.setText(bean.getStrategyTitleStr());

        viewHolder.nicknameText.setText(bean.getNicknameStr());

        return view;
    }

    private void resetViewHolder(ViewHolder holder){
        holder.strategyTitleText.setText(null);
        holder.nicknameText.setText(null);
    }
    private class ViewHolder{
        private TextView strategyTitleText;

        private TextView nicknameText;
    }
}
